package se.haaga.jsupervisor.test.linux;

import java.util.Map;

import se.haaga.jsupervision.monitor.linux.LinuxMonitor;
import se.haaga.jsupervision.monitor.linux.LinuxMonitor.LinuxVariables;

public class ParseLinuxData {
	
	private LinuxMonitor linuxMonitor = null;
	
	public ParseLinuxData() {
		linuxMonitor = new LinuxMonitor("localhost", System.getProperty("user.name"), 22);
		linuxMonitor.openConnection();
		parseMemData();
		parseDistData();
		parseCPUData();
		parseDriveData();
		linuxMonitor.closeConnection();
	}
	
	private void parseDistData() {
		Map<LinuxVariables, String> variables = linuxMonitor.getSystemInformation();
		System.out.println(variables.get(LinuxVariables.DISTRIBUTION_ID));
		System.out.println(variables.get(LinuxVariables.DISTRIBUTION_RELEASE));
		System.out.println(variables.get(LinuxVariables.DISTRIBUTION_DESCRIPTION));
		System.out.println(variables.get(LinuxVariables.DISTRIBUTION_DESCRIPTION));
		System.out.println(variables.get(LinuxVariables.KERNEL_VERSION));
		System.out.println(variables.get(LinuxVariables.UPTIME));
	}

	private void parseDriveData() {
		Map<LinuxVariables, String> variables = linuxMonitor.getDriveInfo();
		System.out.println(variables.get(LinuxVariables.DRIVE_SPACE));
	}

	private void parseCPUData() {
		Map<LinuxVariables, String> variables = linuxMonitor.getCPULoad();
		System.out.println(variables.get(LinuxVariables.TOTAL_CPUS_FOUND));
		System.out.println(variables.get(LinuxVariables.CPU_LOAD));
	}

	private void parseMemData() {
		Map<LinuxVariables, Integer> variables = linuxMonitor.getMemoryStatus();
		System.out.println("totalRam: " + variables.get(LinuxVariables.SYS_MEM_TOTAL));
		System.out.println("usedRam: " + variables.get(LinuxVariables.SYS_MEM_AVAILABLE));
		System.out.println("totalSwap: " + variables.get(LinuxVariables.SWAP_TOTAL));
		System.out.println("usedSwap: " + variables.get(LinuxVariables.SWAP_AVAILABLE));
	}

	public static void main(String[] args) {
		new ParseLinuxData();
	}

}
